using System.Collections.Generic;
using UnityEngine;

public class PlayerInput : MonoBehaviour
{
	public KeyCode Key_Up = (KeyCode)273;

	public KeyCode Key_Down = (KeyCode)274;

	public KeyCode Key_Left = (KeyCode)276;

	public KeyCode Key_Right = (KeyCode)275;

	public KeyCode Key_Confirm = (KeyCode)122;

	public KeyCode Key_Cancel = (KeyCode)120;

	public KeyCode Key_Menu = (KeyCode)99;

	public KeyCode Key_Pause = (KeyCode)27;

	public KeyCode Key_Sprint = (KeyCode)304;

	public static Vector2 MovementInput;

	private Dictionary<KeyCode, bool> keyStates = new Dictionary<KeyCode, bool>();

	private static PlayerInput instance;

	public static PlayerInput Instance => instance;

	private void Awake()
	{
		if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		instance = this;
		Object.DontDestroyOnLoad((Object)(object)instance);
		LoadKeybinding();
	}

	private void Update()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		CacheKeyState(Key_Up);
		CacheKeyState(Key_Down);
		CacheKeyState(Key_Left);
		CacheKeyState(Key_Right);
		CacheKeyState(Key_Sprint);
		MovementInput = GetMovementInput();
	}

	private void CacheKeyState(KeyCode key)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		keyStates[key] = Input.GetKey(key);
	}

	public bool IsKeyHeld(KeyCode key)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		bool value;
		return keyStates.TryGetValue(key, out value) && value;
	}

	public static void LoadKeybinding()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		instance.Key_Up = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Up", 273);
		instance.Key_Left = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Left", 276);
		instance.Key_Right = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Right", 275);
		instance.Key_Down = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Down", 274);
		instance.Key_Confirm = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Confirm", 122);
		instance.Key_Cancel = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Cancel", 120);
		instance.Key_Menu = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Menu", 99);
		instance.Key_Sprint = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Sprint", 304);
		instance.Key_Pause = (KeyCode)PlayerPrefs.GetInt("Setting_Key_Pause", 27);
	}

	public static void RevertToDefaults()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected I4, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected I4, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected I4, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected I4, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected I4, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected I4, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected I4, but got Unknown
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected I4, but got Unknown
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected I4, but got Unknown
		instance.Key_Up = (KeyCode)273;
		instance.Key_Left = (KeyCode)276;
		instance.Key_Right = (KeyCode)275;
		instance.Key_Down = (KeyCode)274;
		instance.Key_Confirm = (KeyCode)122;
		instance.Key_Cancel = (KeyCode)120;
		instance.Key_Menu = (KeyCode)99;
		instance.Key_Sprint = (KeyCode)304;
		instance.Key_Pause = (KeyCode)27;
		PlayerPrefs.SetInt("Setting_Key_Up", (int)instance.Key_Up);
		PlayerPrefs.SetInt("Setting_Key_Left", (int)instance.Key_Left);
		PlayerPrefs.SetInt("Setting_Key_Right", (int)instance.Key_Right);
		PlayerPrefs.SetInt("Setting_Key_Down", (int)instance.Key_Down);
		PlayerPrefs.SetInt("Setting_Key_Confirm", (int)instance.Key_Confirm);
		PlayerPrefs.SetInt("Setting_Key_Cancel", (int)instance.Key_Cancel);
		PlayerPrefs.SetInt("Setting_Key_Menu", (int)instance.Key_Menu);
		PlayerPrefs.SetInt("Setting_Key_Sprint", (int)instance.Key_Sprint);
		PlayerPrefs.SetInt("Setting_Key_Pause", (int)instance.Key_Pause);
		PlayerPrefs.Save();
	}

	public static bool HoldingAnyImportantKeys()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected I4, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected I4, but got Unknown
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected I4, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected I4, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected I4, but got Unknown
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected I4, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected I4, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected I4, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected I4, but got Unknown
		KeyCode[] array = (KeyCode[])(object)new KeyCode[9]
		{
			(KeyCode)(int)instance.Key_Up,
			(KeyCode)(int)instance.Key_Down,
			(KeyCode)(int)instance.Key_Left,
			(KeyCode)(int)instance.Key_Right,
			(KeyCode)(int)instance.Key_Confirm,
			(KeyCode)(int)instance.Key_Cancel,
			(KeyCode)(int)instance.Key_Menu,
			(KeyCode)(int)instance.Key_Sprint,
			(KeyCode)(int)instance.Key_Pause
		};
		for (int i = 0; i < array.Length; i++)
		{
			if (Input.GetKey(array[i]))
			{
				return true;
			}
		}
		return false;
	}

	public static float GetHorizontalInput()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Instance.IsKeyHeld(Instance.Key_Left);
		bool flag2 = Instance.IsKeyHeld(Instance.Key_Right);
		if (flag && !flag2)
		{
			return -1f;
		}
		if (flag2 && !flag)
		{
			return 1f;
		}
		return 0f;
	}

	public static float GetVerticalInput()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Instance.IsKeyHeld(Instance.Key_Up);
		bool flag2 = Instance.IsKeyHeld(Instance.Key_Down);
		if (flag && !flag2)
		{
			return 1f;
		}
		if (flag2 && !flag)
		{
			return -1f;
		}
		return 0f;
	}

	public static Vector2 GetMovementInput()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		bool num = Instance.IsKeyHeld(Instance.Key_Left);
		bool flag = Instance.IsKeyHeld(Instance.Key_Right);
		bool flag2 = Instance.IsKeyHeld(Instance.Key_Up);
		bool flag3 = Instance.IsKeyHeld(Instance.Key_Down);
		float num2 = 0f;
		float num3 = 0f;
		if (num)
		{
			num2 -= 1f;
		}
		if (flag)
		{
			num2 += 1f;
		}
		if (flag2)
		{
			num3 += 1f;
		}
		if (flag3)
		{
			num3 -= 1f;
		}
		Vector2 val = new Vector2(num2, num3);
		return ((Vector2)(ref val)).normalized;
	}
}
